package cn.home.resident.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.home.resident.domain.HomeHealthlog;
import cn.home.resident.mapper.HomeHealthlogMapper;
import cn.home.resident.service.IHomeHealthlogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;


import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 健康记录Controller
 * 
 * @author homedoctor
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/healthlog/healthlog")

public class HomeHealthlogController extends BaseController
{
    @Autowired
    private HomeHealthlogMapper homeHealthlogMapper;
    @Autowired
    private IHomeHealthlogService homeHealthlogService;

    /**
     * 查询健康记录列表
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeHealthlog homeHealthlog)
    {
        startPage();
        List<HomeHealthlog> list = homeHealthlogService.selectHomeHealthlogList(homeHealthlog);
        return getDataTable(list);
    }

    /**
     * 导出健康记录列表
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:export')")
    @Log(title = "健康记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeHealthlog homeHealthlog)
    {
        List<HomeHealthlog> list = homeHealthlogService.selectHomeHealthlogList(homeHealthlog);
        ExcelUtil<HomeHealthlog> util = new ExcelUtil<HomeHealthlog>(HomeHealthlog.class);
        util.exportExcel(response, list, "健康记录数据");
    }
    /**
     * 查询健康记录列表
     * */
    @GetMapping("/selectByUseridAndTypeid")
    public List<HomeHealthlog> getHomeHealthlogListByUseridAndTypeid(
            @RequestParam Long userid,
            @RequestParam Long typeid) {
        return homeHealthlogService.selectHomeHealthlogByUseridAndTypeid(userid, typeid);
    }
    /**
     * 获取健康记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(homeHealthlogService.selectHomeHealthlogById(id));
    }
    /**
     * 获取健康记录匪类信息
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:query')")
    @GetMapping(value = "/getlogtype")
    public TableDataInfo getlogtype(Integer userid,Integer typeid)
    {
        startPage();
        List<HomeHealthlog> selectlog = homeHealthlogMapper.selectlog(userid, typeid);
        return getDataTable(selectlog);
    }

    /**
     * 新增健康记录
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:add')")
    @Log(title = "健康记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeHealthlog homeHealthlog)
    {
        return toAjax(homeHealthlogService.insertHomeHealthlog(homeHealthlog));
    }

    /**
     * 修改健康记录
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:edit')")
    @Log(title = "健康记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeHealthlog homeHealthlog)
    {
        return toAjax(homeHealthlogService.updateHomeHealthlog(homeHealthlog));
    }

    /**
     * 删除健康记录
     */
    @PreAuthorize("@ss.hasPermi('healthlog:healthlog:remove')")
    @Log(title = "健康记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(homeHealthlogService.deleteHomeHealthlogByIds(ids));
    }

}
